﻿/*
Copyright (C) 2012 Laurent Tardif (laurent.tardif@persistentsas.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace org.codeplex.TestUtils
{
    /// <summary>
    ///  helper class to validate some result on a file base
    ///   two files have same content, the (text) file contains a string, .....
    /// </summary>
    public class FileUtils
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pGeneratedFile"></param>
        /// <param name="pReferenceFile"></param>
        /// <returns></returns>
         public static Boolean checkFileAreEquals(String pGeneratedFile,String pReferenceFile) {

             String content1 = File.ReadAllText(pGeneratedFile);
             String content2 = File.ReadAllText(pReferenceFile);

             if (content1.Length != content2.Length)
             {
                 Console.WriteLine("Two length are not equals : " + content1.Length + "," + content2.Length);
                 return false;
             }
             for (int i = 0; i < content1.Length; i++)
             {
                 if (!content1[i].Equals(content2[i]))
                 {
                     Console.WriteLine("both content are not equals " + content1[i] + "," + content2[i]);
                     return false; 
                 }
             }
             
             return true;
         }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="toBeChecked"></param>
        /// <returns></returns>
         public static Boolean CheckContains(String fileName, String toBeChecked)
         {
             String content1 = File.ReadAllText(fileName);
             return StringUtils.CheckContains(content1,toBeChecked);

         }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="toBeChecked"></param>
        /// <returns></returns>
         public static Boolean CheckDoNotContains(String fileName, String toBeChecked)
         {
             String content1 = File.ReadAllText(fileName);
             return StringUtils.CheckDoNotContains(content1, toBeChecked);
         }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="toBeChecked"></param>
        /// <param name="NbMacOccurence"></param>
        /// <returns></returns>
         public static Boolean CheckExactOccurence(String fileName, String toBeChecked, int NbMacOccurence)
         {
             String content1 = File.ReadAllText(fileName);
             return StringUtils.CheckExactOccurence(content1, toBeChecked, NbMacOccurence);
         }

  
    }
}
